#ifndef __STORMWIDGET_STORMWIDGET_UILIBRARY_CMARKUP_MARKUP_H
#define __STORMWIDGET_STORMWIDGET_UILIBRARY_CMARKUP_MARKUP_H

class CMarkupNode;

class CMarkup
{
	friend CMarkupNode;
public:
	CMarkup(LPCTSTR pstrXML = NULL);
	~CMarkup(void);

	bool Load(LPCTSTR pstrXML);
	bool LoadFromFile(LPCTSTR pstrFilename);
	void Release();
	bool IsValid() const;
	void SetPreserveWhitespace(bool bPreserve = true);
	void GetLastErrorMessage(LPTSTR pstrMessage,SIZE_T cchMax) const;
	void GetLastErrorLocation(LPTSTR pstrSource,SIZE_T cchMax) const;
	CMarkupNode GetRoot();
private:
	typedef struct tagXMLELEMENT
	{
		ULONG iStart;
		ULONG iChild;
		ULONG iNext;
		ULONG iParent;
		ULONG iData;
	}XMLELEMENT;

	LPTSTR m_pstrXML;
	XMLELEMENT* m_pElements;
	ULONG m_nElements;
	ULONG m_nReservedElements;
	TCHAR m_szErrorMsg[100];
	TCHAR m_szErrorXML[50];
	bool m_bPreserveWhitespace;
private:
	bool _Parse();
	bool _Parse(LPTSTR& pstrText,ULONG iParent);
	XMLELEMENT* _ReserveElement();
	/*inline */void _SkipWhitespace(LPTSTR& pstr) const;
	/*inline */void _SkipWhitespace(LPCTSTR& pstr) const;
	/*inline */void _SkipIdentifier(LPTSTR& pstr) const;
	/*inline */void _SkipIdentifier(LPCTSTR& pstr) const;
	bool _ParseData(LPTSTR& pstrText,LPTSTR& pstrData,char cEnd);
	void _ParseMetaChar(LPTSTR& pstrText,LPTSTR& pstrDest);
	bool _ParseAttributes(LPTSTR& pstrText);
	bool _Failed(LPCTSTR pstrError,LPCTSTR pstrLocation = NULL);

};
#endif //__STORMWIDGET_STORMWIDGET_UILIBRARY_CMARKUP_MARKUP_H
